package com.gtlab1207.br_awareness.common;

import java.text.SimpleDateFormat;
import java.util.Date;

public class StringUtil {

        public static String autoId(String type,String Dbid,int idSize){
            //存放最终生成的id
            String id = new String();
            //存放计算的编号尾数
            String temp = new String();

            String date = new SimpleDateFormat("yyyyMMdd").format(new Date(System.currentTimeMillis()));
            String str = type+date;
            if("".equals(Dbid)||Dbid==null){
                //如果id不存在，则设置每天的第一个id
                temp = "1";
            }else {
                //取出流水号
                int maxNum = 0;
                for(int i=0;i<=idSize;i++){
                    maxNum += 9*(10^i);
                }
                temp = Dbid.substring(Dbid.length()-idSize,Dbid.length());
                if(Integer.parseInt(temp) >= 1 && Integer.parseInt(temp)<=maxNum){
                    temp = String.valueOf(Integer.parseInt(temp)+1);
                }
            }
            Integer tempSize = temp.length();
            for(int i=0;i<idSize-tempSize;i++){
                temp ="0"+temp;
            }

            id = str+temp;
            return id;

        }
}
